package put.poznan.qmese.matlab.model;

public class Substract extends Operation {

	@Override
	public Matrix calculate() throws CalculationException {
		Matrix mA = Memory.getMatrix(getMatrixA());
		Matrix mB = Memory.getMatrix(getMatrixB());
		
		if (mA.getN() != mB.getN()
				|| mA.getM() != mB.getM()){
			throw new CalculationException("Different dimensions");
		}
		int n = mA.getN();
		int m = mA.getM();
		
		Matrix result = new Matrix();
		result.initialize(n, m);
		
		for (int i=0; i<n; i++){
			for (int j=0; j<m; j++){
				result.set(i, j, mA.get(i, j)-mB.get(i,j));
			}
		}
		return result;
	}
}
